package com.member.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.member.shop.domain.SysBizRecommendCategory;
import org.springframework.security.access.prepost.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.enums.BusinessType;
import com.member.shop.domain.SysBizUserSurplusDetails;
import com.member.shop.service.ISysBizUserSurplusDetailsService;
import com.member.common.utils.poi.ExcelUtil;
import com.member.common.core.page.TableDataInfo;

/**
 * 【用户余额明细】控制器
 *
 * @author wangxin
 * @version 1.0
 * @date 2025-01-16
 **/
@RestController
@RequestMapping("/shop/surplusDetails")
public class SysBizUserSurplusDetailsController extends BaseController {
    @Resource
    private ISysBizUserSurplusDetailsService sysBizUserSurplusDetailsService;

    private void setTenantId(SysBizUserSurplusDetails sysBizUserSurplusDetails) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizUserSurplusDetails.setTenantId(tenantId);
        }
    }

    /**
     * 查询用户余额明细列表
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizUserSurplusDetails sysBizUserSurplusDetails) {
        startPage();
        setTenantId(sysBizUserSurplusDetails);
        List<SysBizUserSurplusDetails> list = sysBizUserSurplusDetailsService.selectSysBizUserSurplusDetailsList(sysBizUserSurplusDetails);
        return getDataTable(list);
    }

    /**
     * 导出用户余额明细列表
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:export')")
    @Log(title = "用户余额明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizUserSurplusDetails sysBizUserSurplusDetails) {

        setTenantId(sysBizUserSurplusDetails);
        List<SysBizUserSurplusDetails> list = sysBizUserSurplusDetailsService.selectSysBizUserSurplusDetailsList(sysBizUserSurplusDetails);
        ExcelUtil<SysBizUserSurplusDetails> util = new ExcelUtil<SysBizUserSurplusDetails>(SysBizUserSurplusDetails.class);
        util.exportExcel(response, list, "用户余额明细数据");
    }

    /**
     * 获取用户余额明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizUserSurplusDetailsService.selectSysBizUserSurplusDetailsById(id));
    }

    /**
     * 新增用户余额明细
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:add')")
    @Log(title = "用户余额明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizUserSurplusDetails sysBizUserSurplusDetails) {
        return toAjax(sysBizUserSurplusDetailsService.insertSysBizUserSurplusDetails(sysBizUserSurplusDetails));
    }

    /**
     * 修改用户余额明细
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:edit')")
    @Log(title = "用户余额明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizUserSurplusDetails sysBizUserSurplusDetails) {
        return toAjax(sysBizUserSurplusDetailsService.updateSysBizUserSurplusDetails(sysBizUserSurplusDetails));
    }

    /**
     * 删除用户余额明细
     */
    @PreAuthorize("@ss.hasPermi('shop:surplusDetails:remove')")
    @Log(title = "用户余额明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizUserSurplusDetailsService.deleteSysBizUserSurplusDetailsByIds(ids));
    }
}
